/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MENU_LOGIN.java
 *
 * Created on Sep 25, 2010, 11:11:57 PM
 */

package cat200project;

import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;


/**
 *
 * @author akmal
 */
public class MENU_LOGIN extends javax.swing.JFrame {

    String TableNumber = " 1 ";
    String Menucode = " 2001 ";
    boolean order = false;

    /** Creates new form MENU_LOGIN */
    public MENU_LOGIN() {
        super("LOGIN");
        initComponents();
        this.setLocationRelativeTo(null);
        MenuCode.setFocusable(false);
        MenuCode.setText(Menucode);
    }

    MENU_LOGIN(String a,String b)
    {
        super("LOGIN");
        initComponents();
        this.setLocationRelativeTo(null);
        TableNumber = a;
        Menucode = b;
        MenuCode.setText(b);
        MenuCode.setFocusable(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jLayeredPane1 = new javax.swing.JLayeredPane();
        Okbutton = new javax.swing.JButton();
        BackButton = new javax.swing.JButton();
        OrderButton = new javax.swing.JButton();
        ReserveButton = new javax.swing.JButton();
        cancel = new javax.swing.JButton();
        TableSelect = new javax.swing.JComboBox();
        MenuCode = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        Okbutton.setFont(new java.awt.Font("Times New Roman", 1, 12));
        Okbutton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/abstract_0072.jpg"))); // NOI18N
        Okbutton.setText("NEXT");
        Okbutton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        Okbutton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OkbuttonActionPerformed(evt);
            }
        });
        Okbutton.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                OkbuttonKeyPressed(evt);
            }
        });
        Okbutton.setBounds(330, 340, 70, 30);
        jLayeredPane1.add(Okbutton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        BackButton.setFont(new java.awt.Font("Times New Roman", 1, 12));
        BackButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/abstract_0072.jpg"))); // NOI18N
        BackButton.setText("BACK");
        BackButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BackButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BackButtonActionPerformed(evt);
            }
        });
        BackButton.setBounds(410, 340, 70, 30);
        jLayeredPane1.add(BackButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        OrderButton.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        OrderButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/abstract_0072.jpg"))); // NOI18N
        OrderButton.setText("ORDER !");
        OrderButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        OrderButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OrderButtonActionPerformed(evt);
            }
        });
        OrderButton.setBounds(280, 150, 160, 40);
        jLayeredPane1.add(OrderButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        ReserveButton.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        ReserveButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/abstract_0072.jpg"))); // NOI18N
        ReserveButton.setText("MAKE RESERVATION");
        ReserveButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        ReserveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ReserveButtonActionPerformed(evt);
            }
        });
        ReserveButton.setBounds(280, 210, 160, 40);
        jLayeredPane1.add(ReserveButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        cancel.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        cancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/abstract_0072.jpg"))); // NOI18N
        cancel.setText("CANCEL");
        cancel.setEnabled(false);
        cancel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelActionPerformed(evt);
            }
        });
        cancel.setBounds(60, 260, 100, 30);
        jLayeredPane1.add(cancel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        TableSelect.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        TableSelect.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Table 1", "Table 2", "Table 3", "Table 4", "Table 5", "Table 6", "Table 7", "Table 8", "Table 9", "Table 10" }));
        TableSelect.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Table Number", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.ABOVE_TOP, new java.awt.Font("Times New Roman", 1, 12))); // NOI18N
        TableSelect.setEnabled(false);
        TableSelect.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                TableSelectPropertyChange(evt);
            }
        });
        TableSelect.setBounds(40, 120, 150, 50);
        jLayeredPane1.add(TableSelect, javax.swing.JLayeredPane.DEFAULT_LAYER);

        MenuCode.setBackground(new java.awt.Color(204, 255, 255));
        MenuCode.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        MenuCode.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Menu Code", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.ABOVE_TOP, new java.awt.Font("Times New Roman", 1, 12))); // NOI18N
        MenuCode.setEnabled(false);
        MenuCode.setBounds(40, 190, 150, 50);
        jLayeredPane1.add(MenuCode, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jSeparator1.setBounds(0, 80, 500, 30);
        jLayeredPane1.add(jSeparator1, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jSeparator2.setBounds(0, 330, 500, 20);
        jLayeredPane1.add(jSeparator2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jLabel3.setBounds(250, 110, 220, 190);
        jLayeredPane1.add(jLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel2.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("MENU BROWSING");
        jLabel2.setBounds(120, 30, 250, 50);
        jLayeredPane1.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/abstract_0072.jpg"))); // NOI18N
        jLabel1.setBounds(-120, -60, 1010, 540);
        jLayeredPane1.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>                        

    private void BackButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           

        this.setVisible(false);
        new FIRST_SCREEN().setVisible(true);        // TODO add your handling code here:
    }                                          

    private void OkbuttonActionPerformed(java.awt.event.ActionEvent evt) {                                         

        if(order)
        {
            try
            {
                new MENU_SELECTION_MAIN(Menucode, TableNumber).setVisible(true);
            }
            catch (SQLException ex)
            {
                Logger.getLogger(MENU_LOGIN.class.getName()).log(Level.SEVERE, null, ex);
            }
            this.setVisible(false);
        }
        else
        {
            JOptionPane.showMessageDialog(null, "Select Order or Reserve First!");
        }
        // TODO add your handling code here:
    }                                        

    private void OkbuttonKeyPressed(java.awt.event.KeyEvent evt) {                                    
      // TODO add your handling code here:
    }                                   

    private void TableSelectPropertyChange(java.beans.PropertyChangeEvent evt) {                                           
    TableSelect.addItemListener(new ItemListener() {

            public void itemStateChanged(ItemEvent e) {
                if (TableSelect.getSelectedIndex() == 0)
        {
            TableNumber = " 1 ";
            Menucode = " 2001 ";
            MenuCode.setText(Menucode);
        }
        else if ( TableSelect.getSelectedIndex()== 1){
            TableNumber = " 2 ";
            Menucode = " 2002 ";
            MenuCode.setText(Menucode);
        }
        else if (TableSelect.getSelectedIndex() == 2){
            TableNumber = " 3 ";
            Menucode = " 2003 ";
            MenuCode.setText(Menucode);
        }
        else if (TableSelect.getSelectedIndex() == 3){
            TableNumber = " 4 ";
            Menucode = " 2004 ";
            MenuCode.setText(Menucode);
        }
        else if (TableSelect.getSelectedIndex() == 4){
            TableNumber = " 5 ";
            Menucode = " 2005 ";
            MenuCode.setText(Menucode);
        }
        else if (TableSelect.getSelectedIndex() == 5){
            TableNumber = " 6 ";
            Menucode = " 2006 ";
            MenuCode.setText(Menucode);
        }
        else if (TableSelect.getSelectedIndex() == 6){
            TableNumber = " 7 ";
            Menucode = " 2007 ";
            MenuCode.setText(Menucode);
        }
        else if (TableSelect.getSelectedIndex() == 7){
            TableNumber = " 8 ";
            Menucode = " 2008 ";
            MenuCode.setText(Menucode);
        }
        else if (TableSelect.getSelectedIndex() == 8){
            TableNumber = " 9 ";
            Menucode = " 2009 ";
            MenuCode.setText(Menucode);
        }
        else if (TableSelect.getSelectedIndex() == 9){
            TableNumber = " 10 ";
            Menucode = " 2010 ";
            MenuCode.setText(Menucode);
        }
            }
        });            // TODO add your handling code here:
    }                                          

    private void OrderButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
        TableSelect.setEnabled(true);
        MenuCode.setEnabled(true);
        cancel.setEnabled(true);
        ReserveButton.setEnabled(false);

        order = true;
        // TODO add your handling code here:
    }                                           

    private void ReserveButtonActionPerformed(java.awt.event.ActionEvent evt) {                                              
        
        if(order){}
        else
        {
            try
            {
                new CUS_RESERVATION().setVisible(true);
            }
            catch (SQLException ex)
            {
                Logger.getLogger(MENU_LOGIN.class.getName()).log(Level.SEVERE, null, ex);
            }
            this.setVisible(false);
        }
        // TODO add your handling code here:
    }                                             

    private void cancelActionPerformed(java.awt.event.ActionEvent evt) {                                       

        TableSelect.setEnabled(false);
        MenuCode.setEnabled(false);
        ReserveButton.setEnabled(true);
        cancel.setEnabled(false);
        // TODO add your handling code here:
    }                                      

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MENU_LOGIN().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton BackButton;
    private javax.swing.JTextField MenuCode;
    private javax.swing.JButton Okbutton;
    private javax.swing.JButton OrderButton;
    private javax.swing.JButton ReserveButton;
    private javax.swing.JComboBox TableSelect;
    private javax.swing.JButton cancel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    // End of variables declaration                   

}
